package cn.itcast.scala.course04

/**
  * 类的定义和使用
  * create by zhangtian on 2018/12/29
  */
object SimpleObjectApp {
  def main(args: Array[String]): Unit = {
    val person = new Person()
    person.name = "Messi"
    println(person.name + " : " +person.age)

    println(person.eat)
    person.watchFootball("zhangtian")
    person.printInfo()
  }

  /**
    * var 属性会自动有get set方法
    * val 属性只有get方法
    */
  class Person {
    // 定义属性
    var name: String = _ // 使用占位符  类型必须要加上，String占位符默认null
    val age = 10 // 自动类型推断
    private [this] val gender = "male" // 私有变量对象不能直接访问，不可见

    def eat(): String ={
      name + " eating......"
    }

    def printInfo(): Unit ={
      println("gender is : "+gender)
    }

    def watchFootball(teamName: String): Unit ={
      println(name + " is watch of " + teamName)
    }
  }
}
